import request  from '@/utils/request';
import { defineStore } from 'pinia';
import { GoodsInfo } from '@/types/goods'
import { ApiRes } from '@/types/data'
export default defineStore('goods', {
  state() {
    return {
      // 商品信息
      info: {} as GoodsInfo
    }
  },
  actions: {
    // 获取商品详情
    async getGoodsInfo(id: string) {
      const res = await request.get<ApiRes<GoodsInfo>>('/goods', {
        params: {
          id
        }
      })
      console.log('---商品的数据res--', res.data);
      this.info = res.data.result
    },
    // 重置商品信息
    resetGoodsInfo() {
      this.info = {} as GoodsInfo
    }
  }
})